/**
 * Created by Jie on 2017/1/2.
 */
$(document).ready(
    function() {
        setTimeout("p1()",500);
        setTimeout("p2()",500);
        setTimeout("p3()",500);
        setTimeout("p4()",500);
        setTimeout("p5()",500);
        var nowpage = 0;
        //给最大的盒子增加事件监听
        $(".container").swipe(
            {
                swipe:function(event, direction, distance, duration, fingerCount) {
                    if(direction == "up"){
                        nowpage = nowpage + 1;
                    }else if(direction == "down"){
                        nowpage = nowpage - 1;
                    }
                    if(nowpage == 0){
                        setTimeout("p1()",500);
                        setTimeout("p2()",500);
                        setTimeout("p3()",500);
                        setTimeout("p4()",500);
                        setTimeout("p5()",500);
                    }else {
                        $('.page1-txt').hide();
                    }
                    if(nowpage > 4){
                        nowpage = 4;
                    }

                    if(nowpage < 0){
                        nowpage = 0;
                    }
                    if(nowpage == 4){
                        $('.tips').attr("src","images/up.png");
                    }else{
                        $('.tips').attr("src","images/down.png");
                    }
                    $(".container").animate({"top":nowpage * -100 + "%"},400);

                    $(".page").eq(nowpage).addClass("cur").siblings().removeClass("cur");
                }
            }
        );
    }
);

function down(_id) {
    var id = '#'+_id;
    $(id).slideDown();
}
function p1() {
    down('p1');
}
function p2() {
    down('p2');
}
function p3() {
    down('p3');
}
function p4() {
    down('p4');
}
function p5() {
    down('p5');
}